package com.chahua.organized.common;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Min;
import java.io.Serializable;
import java.util.List;

/**
 * @author chahua
 * @date 2022/4/9 22:53
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "分页数据")
public class PageData<T> implements Serializable {

    private static final long serialVersionUID = -2145950683457901152L;

    @ApiModelProperty(value = "分页页码")
    @Min(value = 1, message = "页码需要从1开始")
    private int pageNum;

    @ApiModelProperty(value = "分页页面条数")
    @Min(value = 1, message = "分页条数需要从1开始")
    private int pageSize;

    @ApiModelProperty(value = "查询出来的总条数")
    private long totalCount;

    @ApiModelProperty(value = "数据")
    private List<T> data;

    public void addPageInfo(PageInfo<T> pageInfo) {
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.totalCount = pageInfo.getTotal();
        this.data = pageInfo.getList();
    }
}
